package yxy.game.pm2.bean.db.dao;

import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import yxy.apple.database.BaseDAO;
import yxy.apple.database.DAOGameManager;
import yxy.apple.database.DAOManager;
import yxy.game.pm2.bean.db.module.account;
import yxy.game.pm2.bean.db.module.cache;

public class MySQLAccountDAO extends BaseDAO<account> {

	//专服里的用户
	public static account getByClusterId(String name, int clusterId) {
		try {
			Map<String, Object> params = new Hashtable<>();
			params.put("name", name);
			params.put("clusterid", clusterId);
			String sql = "select * from account where clusterid=:clusterid and `name`=:name  limit 1";
			List<account> list = queryBySql(DAOManager.getGameH(), account.class, sql, params);
			return (list != null && list.size() > 0) ? list.get(0) : null;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public static account get(String name) {
		try {
			List<account> list = queryByKey(DAOManager.getGameH(), "account", "name", name);
			return (list != null && list.size() > 0) ? list.get(0) : null;
		} catch (Exception e) {
			return null;
		}
	}

	public static account get(int accountId) {
		return get(DAOManager.getGameH(), account.class, accountId);
	}

	public static boolean add(account db) {
		return MySQLAccountDAO.add(DAOManager.getGameH(), db);
	}

	public static boolean update(account db) {
		return MySQLAccountDAO.update(DAOManager.getGameH(), db);
	}
}
